package net.zjitc;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

/**
 * @author 3505
 * @version 1.0
 * @date 2018/6/27
 */
public class SendTask implements Runnable {
    private int sendPort;
    public SendTask(int sendPort) {
        this.sendPort=sendPort;
    }

    @Override
    public void run() {
        try {
            DatagramSocket ds=new DatagramSocket();
            Scanner in =new Scanner(System.in);
            while(true){
                String data=in.next();
                byte[] buff=data.getBytes();
                DatagramPacket dp=new DatagramPacket(buff,buff.length, InetAddress.getByName("Localhost"),sendPort);
                ds.send(dp);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
